<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<PropertyGroup>
		<BuildRootDir>..\Build</BuildRootDir>
		<BuildDir>$(BuildRootDir)\bin</BuildDir>
		<BuildTestDir>$(BuildRootDir)\Test</BuildTestDir>
		<LibDir>$(BuildRootDir)\lib</LibDir>
		<NET45Folder>NET Framework 4.5</NET45Folder>
		<NET40Folder>NET Framework 4.0</NET40Folder>
		<NET35Folder>NET Framework 3.5</NET35Folder>
		<NET30Folder>NET Framework 3.0</NET30Folder>
		<NET20Folder>NET Framework 2.0</NET20Folder>
		<XMLFile>Navigation.xml</XMLFile>
		<CodeAnalysis>true</CodeAnalysis>
	</PropertyGroup>
	<!-- Delete previous files from target folder -->
	<Target Name="DeleteAll">
		<ItemGroup>
			<All Include="$(BuildRootDir)\**\*"/>
		</ItemGroup>
		<Delete Files="@(All)" />
	</Target>
	<!-- Release Build Navigation passing target framework and corresponding constants -->
	<Target Name="BuildNavigation">
		<MSBuild Projects="Navigation\Navigation.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v4.5; OutputPath=..\$(BuildDir)\$(NET45Folder);
				 Configuration=Release; DefineConstants=NET35Plus;NET40Plus;NET45Plus; RunCodeAnalysis=$(CodeAnalysis);
				 TreatWarningsAsErrors=true; DocumentationFile=..\$(BuildDir)\$(NET45Folder)\$(XMLFile);" />
		<MSBuild Projects="Navigation\Navigation.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v4.0; OutputPath=..\$(BuildDir)\$(NET40Folder);
				 Configuration=Release; DefineConstants=NET35Plus;NET40Plus; RunCodeAnalysis=$(CodeAnalysis);
				 TreatWarningsAsErrors=true; DocumentationFile=..\$(BuildDir)\$(NET40Folder)\$(XMLFile);" />
		<MSBuild Projects="Navigation\Navigation.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v3.5; OutputPath=..\$(BuildDir)\$(NET35Folder);
				 Configuration=Release; DefineConstants=NET35Plus; RunCodeAnalysis=$(CodeAnalysis);
				 TreatWarningsAsErrors=true; DocumentationFile=..\$(BuildDir)\$(NET35Folder)\$(XMLFile);" />
		<MSBuild Projects="Navigation\Navigation.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v3.0; OutputPath=..\$(BuildDir)\$(NET30Folder);
				 Configuration=Release; DefineConstants=; RunCodeAnalysis=$(CodeAnalysis); TreatWarningsAsErrors=true;
				 DocumentationFile=..\$(BuildDir)\$(NET30Folder)\$(XMLFile);" />
		<MSBuild Projects="Navigation\Navigation.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v2.0; OutputPath=..\$(BuildDir)\$(NET20Folder);
				 Configuration=Release; DefineConstants=; RunCodeAnalysis=$(CodeAnalysis); TreatWarningsAsErrors=true;
				 DocumentationFile=..\$(BuildDir)\$(NET20Folder)\$(XMLFile);" />
	</Target>
	<!-- Release build Navigation.Test passing fixed framework 4.5, because MSTest doesn't
	work prior to 4.0, but correct constants -->
	<Target Name="BuildNavigationTest">
		<MSBuild Projects="Navigation.Test\Navigation.Test.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v4.5; OutputPath=..\$(BuildTestDir)\$(NET45Folder);
				 Configuration=Release; DefineConstants=NET35Plus;NET40Plus;NET45Plus;" />
		<MSBuild Projects="Navigation.Test\Navigation.Test.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v4.5; OutputPath=..\$(BuildTestDir)\$(NET40Folder);
				 Configuration=Release; DefineConstants=NET35Plus;NET40Plus;" />
		<MSBuild Projects="Navigation.Test\Navigation.Test.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v4.5; OutputPath=..\$(BuildTestDir)\$(NET35Folder);
				 Configuration=Release; DefineConstants=NET35Plus;" />
		<MSBuild Projects="Navigation.Test\Navigation.Test.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v4.5; OutputPath=..\$(BuildTestDir)\$(NET30Folder);
				 Configuration=Release; DefineConstants=" />
		<MSBuild Projects="Navigation.Test\Navigation.Test.csproj" Targets="Rebuild"
				 Properties="TargetFrameworkVersion=v4.5; OutputPath=..\$(BuildTestDir)\$(NET20Folder);
				 Configuration=Release; DefineConstants=" />
	</Target>
	<!-- Delete code analysis generated files -->
	<Target Name="DeleteCodeAnalysis">
		<ItemGroup>
			<CodeAnalysis Include="$(BuildRootDir)\**\*CodeAnalysis*"/>
		</ItemGroup>
		<Delete Files="@(CodeAnalysis)" />
	</Target>
	<!-- Copy Navigation files into lib directory for NuGet -->
	<Target Name="CopyNavigation">
		<ItemGroup>
			<Navigation45 Include="$(BuildDir)\$(NET45Folder)\Navigation.dll;$(BuildDir)\$(NET45Folder)\$(XMLFile)"/>
			<Navigation40 Include="$(BuildDir)\$(NET40Folder)\Navigation.dll;$(BuildDir)\$(NET40Folder)\$(XMLFile)"/>
			<Navigation35 Include="$(BuildDir)\$(NET35Folder)\Navigation.dll;$(BuildDir)\$(NET35Folder)\$(XMLFile)"/>
			<Navigation30 Include="$(BuildDir)\$(NET30Folder)\Navigation.dll;$(BuildDir)\$(NET30Folder)\$(XMLFile)"/>
			<Navigation20 Include="$(BuildDir)\$(NET20Folder)\Navigation.dll;$(BuildDir)\$(NET20Folder)\$(XMLFile)"/>
		</ItemGroup>
		<Copy SourceFiles="@(Navigation45)" DestinationFolder="$(LibDir)\4.5" />
		<Copy SourceFiles="@(Navigation40)" DestinationFolder="$(LibDir)\4.0" />
		<Copy SourceFiles="@(Navigation35)" DestinationFolder="$(LibDir)\3.5" />
		<Copy SourceFiles="@(Navigation30)" DestinationFolder="$(LibDir)\3.0" />
		<Copy SourceFiles="@(Navigation20)" DestinationFolder="$(LibDir)\2.0" />
	</Target>
	<!-- Replace Navigation.dll's generated by Navigation.Test build with those from Navigation 
		build so the correct target framework is used -->
	<Target Name="ReplaceTestNavigation">
		<ItemGroup>
			<Bin Include="$(BuildDir)\**\Navigation.dll"/>
		</ItemGroup>
		<Copy SourceFiles="@(Bin)" DestinationFolder="$(BuildTestDir)\%(RecursiveDir)" />
	</Target>
	<!-- Run unit tests -->
	<Target Name="RunTests">
		<Exec Command='"mstest.exe" /testcontainer:"$(BuildTestDir)\$(NET45Folder)\Navigation.Test.dll"' />
		<Exec Command='"mstest.exe" /testcontainer:"$(BuildTestDir)\$(NET40Folder)\Navigation.Test.dll"' />
		<Exec Command='"mstest.exe" /testcontainer:"$(BuildTestDir)\$(NET35Folder)\Navigation.Test.dll"' />
		<Exec Command='"mstest.exe" /testcontainer:"$(BuildTestDir)\$(NET30Folder)\Navigation.Test.dll"' />
		<Exec Command='"mstest.exe" /testcontainer:"$(BuildTestDir)\$(NET20Folder)\Navigation.Test.dll"' />
	</Target>
	<!-- Top level task: msbuild build.xml /t:Navigate -->
	<Target Name="Navigate" DependsOnTargets="DeleteAll;BuildNavigation;BuildNavigationTest;DeleteCodeAnalysis;
			CopyNavigation;ReplaceTestNavigation;RunTests">
	</Target>
</Project>

